from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-01 14:02:07.893624
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 01, Apr, 2022
Time: 14:02:12
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.7798
Nobs: 613.000 HQIC: -49.1762
Log likelihood: 7411.55 FPE: 3.41573e-22
AIC: -49.4285 Det(Omega_mle): 2.95281e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.341366 0.065549 5.208 0.000
L1.Burgenland 0.105786 0.040263 2.627 0.009
L1.Kärnten -0.110616 0.021064 -5.251 0.000
L1.Niederösterreich 0.194195 0.084177 2.307 0.021
L1.Oberösterreich 0.119503 0.082905 1.441 0.149
L1.Salzburg 0.259029 0.042702 6.066 0.000
L1.Steiermark 0.041018 0.056353 0.728 0.467
L1.Tirol 0.104329 0.045463 2.295 0.022
L1.Vorarlberg -0.066079 0.040171 -1.645 0.100
L1.Wien 0.018253 0.073874 0.247 0.805
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051102 0.140522 0.364 0.716
L1.Burgenland -0.038102 0.086315 -0.441 0.659
L1.Kärnten 0.042068 0.045156 0.932 0.352
L1.Niederösterreich -0.202140 0.180456 -1.120 0.263
L1.Oberösterreich 0.455222 0.177729 2.561 0.010
L1.Salzburg 0.282752 0.091542 3.089 0.002
L1.Steiermark 0.113311 0.120808 0.938 0.348
L1.Tirol 0.306077 0.097462 3.140 0.002
L1.Vorarlberg 0.026929 0.086116 0.313 0.755
L1.Wien -0.028532 0.158368 -0.180 0.857
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195715 0.033474 5.847 0.000
L1.Burgenland 0.088476 0.020561 4.303 0.000
L1.Kärnten -0.007166 0.010757 -0.666 0.505
L1.Niederösterreich 0.243292 0.042987 5.660 0.000
L1.Oberösterreich 0.160628 0.042337 3.794 0.000
L1.Salzburg 0.040026 0.021806 1.836 0.066
L1.Steiermark 0.027610 0.028778 0.959 0.337
L1.Tirol 0.082509 0.023217 3.554 0.000
L1.Vorarlberg 0.054241 0.020514 2.644 0.008
L1.Wien 0.116584 0.037725 3.090 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115456 0.033507 3.446 0.001
L1.Burgenland 0.042658 0.020581 2.073 0.038
L1.Kärnten -0.013085 0.010767 -1.215 0.224
L1.Niederösterreich 0.173283 0.043029 4.027 0.000
L1.Oberösterreich 0.334958 0.042379 7.904 0.000
L1.Salzburg 0.099877 0.021828 4.576 0.000
L1.Steiermark 0.112775 0.028806 3.915 0.000
L1.Tirol 0.090833 0.023239 3.909 0.000
L1.Vorarlberg 0.060655 0.020534 2.954 0.003
L1.Wien -0.017826 0.037762 -0.472 0.637
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119971 0.062783 1.911 0.056
L1.Burgenland -0.046078 0.038564 -1.195 0.232
L1.Kärnten -0.045432 0.020175 -2.252 0.024
L1.Niederösterreich 0.137898 0.080625 1.710 0.087
L1.Oberösterreich 0.162854 0.079406 2.051 0.040
L1.Salzburg 0.284399 0.040900 6.954 0.000
L1.Steiermark 0.059844 0.053975 1.109 0.268
L1.Tirol 0.159117 0.043545 3.654 0.000
L1.Vorarlberg 0.098124 0.038475 2.550 0.011
L1.Wien 0.071966 0.070756 1.017 0.309
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067667 0.049059 1.379 0.168
L1.Burgenland 0.025223 0.030134 0.837 0.403
L1.Kärnten 0.053060 0.015765 3.366 0.001
L1.Niederösterreich 0.192175 0.063001 3.050 0.002
L1.Oberösterreich 0.332183 0.062048 5.354 0.000
L1.Salzburg 0.035548 0.031959 1.112 0.266
L1.Steiermark 0.010675 0.042176 0.253 0.800
L1.Tirol 0.121053 0.034026 3.558 0.000
L1.Vorarlberg 0.066774 0.030065 2.221 0.026
L1.Wien 0.097047 0.055289 1.755 0.079
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172037 0.059113 2.910 0.004
L1.Burgenland 0.004841 0.036310 0.133 0.894
L1.Kärnten -0.065870 0.018996 -3.468 0.001
L1.Niederösterreich -0.105301 0.075912 -1.387 0.165
L1.Oberösterreich 0.206522 0.074765 2.762 0.006
L1.Salzburg 0.054347 0.038509 1.411 0.158
L1.Steiermark 0.247263 0.050820 4.865 0.000
L1.Tirol 0.502106 0.040999 12.247 0.000
L1.Vorarlberg 0.064108 0.036226 1.770 0.077
L1.Wien -0.077408 0.066620 -1.162 0.245
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155750 0.065522 2.377 0.017
L1.Burgenland -0.002378 0.040246 -0.059 0.953
L1.Kärnten 0.062510 0.021055 2.969 0.003
L1.Niederösterreich 0.168790 0.084142 2.006 0.045
L1.Oberösterreich -0.055355 0.082871 -0.668 0.504
L1.Salzburg 0.207999 0.042684 4.873 0.000
L1.Steiermark 0.139863 0.056330 2.483 0.013
L1.Tirol 0.058370 0.045444 1.284 0.199
L1.Vorarlberg 0.147263 0.040154 3.667 0.000
L1.Wien 0.119931 0.073843 1.624 0.104
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.387855 0.038557 10.059 0.000
L1.Burgenland -0.004441 0.023683 -0.187 0.851
L1.Kärnten -0.020918 0.012390 -1.688 0.091
L1.Niederösterreich 0.202604 0.049514 4.092 0.000
L1.Oberösterreich 0.231671 0.048766 4.751 0.000
L1.Salzburg 0.036493 0.025118 1.453 0.146
L1.Steiermark -0.015226 0.033148 -0.459 0.646
L1.Tirol 0.089296 0.026742 3.339 0.001
L1.Vorarlberg 0.051425 0.023629 2.176 0.030
L1.Wien 0.044137 0.043453 1.016 0.310
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036938 0.109890 0.172701 0.139855 0.102267 0.081849 0.035864 0.211197
Kärnten 0.036938 1.000000 -0.026018 0.130953 0.049266 0.085286 0.443654 -0.066500 0.089813
Niederösterreich 0.109890 -0.026018 1.000000 0.314016 0.121389 0.275087 0.068679 0.154755 0.293140
Oberösterreich 0.172701 0.130953 0.314016 1.000000 0.213509 0.297097 0.166907 0.138279 0.239407
Salzburg 0.139855 0.049266 0.121389 0.213509 1.000000 0.125012 0.093064 0.105957 0.125394
Steiermark 0.102267 0.085286 0.275087 0.297097 0.125012 1.000000 0.135067 0.108854 0.037591
Tirol 0.081849 0.443654 0.068679 0.166907 0.093064 0.135067 1.000000 0.065044 0.150999
Vorarlberg 0.035864 -0.066500 0.154755 0.138279 0.105957 0.108854 0.065044 1.000000 -0.003205
Wien 0.211197 0.089813 0.293140 0.239407 0.125394 0.037591 0.150999 -0.003205 1.000000